package com.gobang.domain.enums;

/**
 * 玩家颜色枚举
 * 
 * @author System
 * @since 1.0.0
 */
public enum PlayerColor {
    
    /**
     * 黑方
     */
    BLACK("BLACK", "黑方", 1),
    
    /**
     * 白方
     */
    WHITE("WHITE", "白方", 2);
    
    private final String code;
    private final String description;
    private final int value;
    
    PlayerColor(String code, String description, int value) {
        this.code = code;
        this.description = description;
        this.value = value;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    public int getValue() {
        return value;
    }
    
    /**
     * 根据代码获取枚举
     *
     * @param code 颜色代码
     * @return 玩家颜色枚举
     */
    public static PlayerColor fromCode(String code) {
        for (PlayerColor color : PlayerColor.values()) {
            if (color.getCode().equals(code)) {
                return color;
            }
        }
        throw new IllegalArgumentException("未知的玩家颜色代码: " + code);
    }
    
    /**
     * 根据值获取枚举
     *
     * @param value 颜色值
     * @return 玩家颜色枚举
     */
    public static PlayerColor fromValue(int value) {
        for (PlayerColor color : PlayerColor.values()) {
            if (color.getValue() == value) {
                return color;
            }
        }
        throw new IllegalArgumentException("未知的玩家颜色值: " + value);
    }
    
    /**
     * 获取对手颜色
     *
     * @return 对手颜色
     */
    public PlayerColor getOpponent() {
        return this == BLACK ? WHITE : BLACK;
    }
} 